package com.qfmy.webapp.task;

import com.qfmy.common.constant.RedisConstant;
import com.qfmy.webapp.mapper.user.SignInRecordMapper;
import com.qfmy.webapp.mapper.user.UserInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author 清风明月
 * @Package com.qfmy.webapp.task
 * @date 2025/11/12
 * @description 用户的定时任务
 */
@Component
@SuppressWarnings("all")
public class UserTask {

    /**
     * 注入StringRedisTemplate
     */
    @Autowired
    private StringRedisTemplate redisTemplate;

    /**
     * 注入用户mapper
     */
    @Autowired
    private UserInfoMapper userMapper;

    /**
     * 更注入签到纪录表
     */
    @Autowired
    private SignInRecordMapper signInRecordMapper;


    /**
     * 每天凌晨清除用户昨天阅读时间
     */
    @Scheduled(cron = "0 0 0 * * ?")
    public void clearYesterdayReadTime() {
        redisTemplate.delete("today_read_time:*");
    }

    /**
     * 每天凌晨清除用户获取的收益
     */
    @Scheduled(cron = "0 0 0 * * ?")
    public void clearYesterdayIncome() {
        String key = RedisConstant.APP_TODAY_SCORE_KEY;
        redisTemplate.delete(key + "*");
    }

    /**
     * 每天凌晨更新用户的签到状态
     */
    @Scheduled(cron = "0 0 0 * * ?")
    public void updateSignInStatus() {
        signInRecordMapper.updateSignInStatus();
    }

}
